import { ref, watch } from "vue";
import encrypt from "@/utils/encrypt.js";
export function useTheme() {
  const theme = ref(encrypt.GetLocalData("theme") || "dark"); // 默认设置为 'dark'

  watch(theme, (newTheme) => {
    encrypt.SetLocalData("theme", newTheme);
    document.documentElement.setAttribute("data-theme", newTheme);
  });

  function setTheme(newTheme) {
    theme.value = newTheme;
  }

  // 初始化主题
  document.documentElement.setAttribute("data-theme", theme.value);

  return {
    theme,
    setTheme,
  };
}
